import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/utils/util.dart';

class ProProgressCell extends StatelessWidget {
  const ProProgressCell({
    Key? key,
    this.isFirst = false,
    this.isLast = false,
    required this.title,
    this.rightTitle,
    required this.content,
    required this.status,
  }) : super(key: key);
  final bool isFirst;
  final bool isLast;
  final int status;
  final String title;
  final String? rightTitle;
  final String content;
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(16.r, 0, 16.r, 0),
      width: Get.width,
      child: Row(
        children: [
          Container(
            height: 116.r,
            child: Column(
              children: [
                Container(
                  color: isFirst ? ColorsUtil.bg : ColorsUtil.content,
                  width: 0.5,
                  height: 50.r,
                ),
                _getIcon(),
                Visibility(
                  visible: !isLast,
                  child: Container(
                    color: isLast ? ColorsUtil.bg : ColorsUtil.content,
                    width: 0.5,
                    height: 50.r,
                  ),
                ),
              ],
            ),
          ),
          Expanded(
            child: Container(
              height: 100.r,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(4.r),
              ),
              margin: EdgeInsets.fromLTRB(16.r, 0, 0, 16.r),
              padding: EdgeInsets.symmetric(horizontal: 16.r, vertical: 20.r),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        title + _getStatusStr(),
                        style:
                            TextStyle(color: _getTitleColor(), fontSize: 15.sp),
                      ),
                      Text(
                        rightTitle ?? '',
                        style:
                            TextStyle(color: ColorsUtil.title, fontSize: 15.sp),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: 10.r,
                  ),
                  Text(
                    status < 2 ? content : (title + _getStatusStr()),
                    style: TextStyle(
                      color: status < 3 ? ColorsUtil.title : ColorsUtil.content,
                      fontSize: 14.sp,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _getIcon() {
    if (status < 2) {
      return Icon(
        Icons.check_circle,
        color: ColorsUtil.green,
        size: 16.r,
      );
    } else if (status == 2) {
      return Icon(
        Icons.info,
        color: ColorsUtil.red,
        size: 16.r,
      );
    }
    return Icon(
      Icons.remove_circle,
      color: ColorsUtil.content,
      size: 16.r,
    );
  }

  Color _getTitleColor() {
    if (status < 2) {
      return ColorsUtil.title;
    } else if (status == 2) {
      return ColorsUtil.red;
    }
    return ColorsUtil.content;
  }

  String _getStatusStr() {
    if (status < 2) {
      return '阶段已完成';
    } else if (status == 2) {
      return '阶段已逾期';
    }
    return '阶段未开始';
  }
}
